import { remote } from 'electron'
import path from 'path'

function getUserData() {
  let configDir = remote.app.getPath('userData');
  return configDir;
}

function getTmpDir() {
  return remote.app.getPath('temp')
}

function getDownloadDir() {
  return remote.app.getPath('downloads')
}

function chooseImages() {
  let paths = remote.dialog.showOpenDialog({
    title: '请选择图片',
    properties: ['openFile', 'multiSelections'],
    filters: [
      { name: 'Images', extensions: ['jpg', 'png', 'jpeg'] },
    ]
  });
  return paths || [];
}

function chooseSingleImage() {
  let paths = remote.dialog.showOpenDialog({
    title: '请选择图片',
    properties: ['openFile'],
    filters: [
      { name: 'Images', extensions: ['jpg', 'png', 'jpeg'] },
    ]
  });
  return paths && paths.length ? paths[0] : '';
}

function chooseSingleAudio() {
  let paths = remote.dialog.showOpenDialog({
    title: '请选择音频',
    properties: ['openFile'],
    filters: [
      { name: 'Audios', extensions: ['aac', 'wav', 'aac', 'm4a', 'mp3', 'mp4'] },
    ]
  });
  return paths && paths.length ? paths[0] : '';
}

function chooseSingleFont() {
  let paths = remote.dialog.showOpenDialog({
    title: '请选择 .ttf 字体文件',
    properties: ['openFile'],
    filters: [
      { name: 'Font', extensions: ['ttf'] },
    ]
  });
  return paths && paths.length ? paths[0] : '';
}

function chooseVideos() {
  let paths = remote.dialog.showOpenDialog({
    title: '请选择视频',
    properties: ['openFile', 'multiSelections'],
    filters: [
      { name: 'Videos', extensions: ['mp4', 'avi', 'mov', 'wmv'] },
    ]
  });
  return paths || [];
}

function showOutputFolder(pathDir) {
  const { shell } = remote;
  shell.showItemInFolder(pathDir);
}

export default {
  getTmpDir,
  getDownloadDir,
  getUserData,
  chooseImages,
  chooseSingleImage,
  showOutputFolder,
  chooseVideos,
  chooseSingleAudio,
  chooseSingleFont,
}